import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import login from "../views/user/login";
import userRegister from "../views/user/userRegister";
import backIndex from "../views/backIndex";
import Information from '../views/Information/Information';
import competitionList from '../views/Information/components/competitionList';
import EventDynamics from '../views/Information/components/EventDynamics';
import announcement from '../views/Information/components/announcement';
import gamesDetails from '../views/Information/components/gamesDetails';
import signUp from '../views/signUp';
import teams from '../views/teams/teams'
import editTeam from '../views/teams/children/editTeam'
import entry from '../views/entry/entry'
import uploading from "../views/entry/children/uploading";
import managementTeam from "../views/managementTeam/managementTeam";
import allTeam from "../views/managementTeam/children/allTeam";
import allwork from "../views/managementTeam/children/allwork";
import issue from "../views/issue/issue";
import ReleaseGames from "../views/ReleaseGames/ReleaseGames";
import InformationRelease from "../views/InformationRelease/InformationRelease";
import AddJudges from "../views/AddJudges/AddJudges";
import judges from "../views/AddJudges/children/judges";
import DynamicArticles from "../views/Information/components/DynamicArticles";
import announcementArticles from "../views/Information/components/announcementArticles";
import accountManagement from "../views/user/accountManagement";
import editAllTeam from "../views/managementTeam/children/editAllTeam";
import deleteNotify from "../views/deleteNotify/deleteNotify";

Vue.use(VueRouter)

const routes = [
  {
    path: '/home',
    name: 'Home',
    component: Home,
    children: [
    ]
  },
  {
    path: '/login',
    component: login
  },
  {
    path: '/userRegister',
    component: userRegister
  },
  {
    path: '/backIndex',
    component: backIndex,
    children: [
      {
        path: 'teams',
        component: teams
      },
      {
        path: 'editTeam',
        component: editTeam
      },
      {
        path: 'entry',
        component: entry
      },
      {
        path: 'uploading',
        component: uploading
      },
      {
        path: 'managementTeam',
        component: managementTeam
      },
      {
        path: 'allTeam',
        component: allTeam
      },
      {
        path: 'issue',
        component: issue
      },
      {
        path: 'allwork',
        component: allwork
      },
      {
        path: 'ReleaseGames',
        component: ReleaseGames
      },
      {
        path: 'InformationRelease',
        component: InformationRelease
      },
      {
        path: 'AddJudges',
        component: AddJudges
      },
      {
        path: 'judges',
        component: judges
      },
      {
        path: 'editAllTeam',
        component: editAllTeam
      },
      {
        path: 'deleteNotify',
        component: deleteNotify
      }
    ]
  },
  {
    path: '/information',
    component: Information,
    children: [
      {
        path:'competitionList',
        component: competitionList
      },
      {
        path: 'EventDynamics',
        component: EventDynamics
      },
      {
        path: 'announcement',
        component: announcement
      },
      {
        path: 'gamesDetails',
        component: gamesDetails
      },
      {
        path: 'DynamicArticles',
        component: DynamicArticles
      },
      {
        path: 'announcementArticles',
        component: announcementArticles
      }
    ]
  },
  {
    path: '/signUp',
    component: signUp
  },
  {
    path: '/accountManagement',
    component: accountManagement
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {undefined
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
//路由导航守卫
router.beforeEach((to, from, next)=>{
  if(to.path==='/login'||to.path==='/userRegister') return next();
  //获取缓存区的token值
  const token = window.sessionStorage.getItem('token');
  // console.log(token);
  if(!token){
    // this.message.error("请先登陆！");
    return next('/login');
  }
  next();
})

export default router
